home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000054_icon-group-sender_Thu Mar 8 08:01:36 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f28F16o23529
for icon-group-addresses; Thu, 8 Mar 2001 08:01:06 -0700 (MST)
Message-Id: <200103081501.f28F16o23529@baskerville.CS.Arizona.EDU>
From: Michael Horsch <horsch@cs.usask.ca>
X-Newsgroups: comp.lang.apl,comp.lang.forth,comp.lang.icon,comp.lang.lisp,comp.lang.mumps,comp.lang.scheme,comp.lang.smalltalk
Subject: Re: New Scientist Puzzle
Date: Wed, 07 Mar 2001 18:21:01 -0600
X-Trace: tribune.usask.ca 984010861 9817 128.233.128.5 (8 Mar 2001 00:21:01 GMT)
X-Complaints-To: usenet@tribune.usask.ca
X-Accept-Language: en
To: icon-group@cs.arizona.edu
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 1038
I coded up a Prolog + CLP(FD) solution. I have a well-documented
version of it available, but since no one else provided comments,
I won't either. :-) The CLP(FD) engine I am using is provided
by Sicstus Prolog. The run time is about 40msec on a Sparc Ultra10.
% sictus prolog file: vn.pl
:- use_module(library(clpfd)).
:- use_module(library(lists)).
solve(P,Q) :-
setof((PP,QQ), pair(PP,QQ), Pairs),
unique(Pairs, (P,Q)).
unique(Pairs, (P,Q)) :-
select((P,Q), Pairs, Rs),
\+ member((P,_), Rs),
\+ member((_,P), Rs),
\+ member((Q,_), Rs),
\+ member((_,Q), Rs).
pair(P,Q) :-
domain([V,I,E,R,N,U], 0, 9),
P #= V*1000 + I*100 + E*10 + R,
Q #= N*1000 + E*100 + U*10 + N,
V #> 0,
N #> 0,
domain([X1,X2,Y1,Y2], 0, 9),
X #= X1*10 + X2,
Y #= Y1*10 + Y2,
X1 #> 0,
Y1 #> 0,
P #= X*X,
Q #= Y*Y,
all_different([V,I,E,R,N,U]),
labeling([], [P,Q]).
% eof
Mike
--
Michael C. Horsch
Department of Computer Science
University of Saskatchewan
http://www.cs.usask.ca/faculty/horsch/home.shtml